home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / progwin.zip / DEVCAPS1.ZIP / DEVCAPS1.C < prev    next >
C/C++ Source or Header  |  1991-11-01  |  4KB  |  162 lines

  1. /*-----------------------------------------------------
  2.   DEVCAPS1.C -- Displays Device Capability Information
  3.                 (c) Charles Petzold, 1990
  4.   -----------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include <string.h>
  8. #include "devcaps1.h"
  9.  
  10. void DoBasicInfo(HDC, HDC, short, short);         // in DEVCAPS.C
  11. void DoOtherInfo(HDC, HDC, short, short);
  12. void DoBitCodedCaps(HDC, HDC, short, short, short);
  13.  
  14. long FAR PASCAL WndProc(HWND, WORD, WORD, LONG) ;
  15.  
  16. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  17.                    LPSTR lpszCmdLine, int nCmdShow)
  18. {
  19.   static char szAppName[] = "DevCaps";
  20.   HWND hwnd;
  21.   MSG msg;
  22.   WNDCLASS wndclass;
  23.  
  24.   if (!hPrevInstance)
  25.   {
  26.     wndclass.style = CS_HREDRAW | CS_VREDRAW;
  27.     wndclass.lpfnWndProc = WndProc;
  28.     wndclass.cbClsExtra = 0;
  29.     wndclass.cbWndExtra = 0;
  30.     wndclass.hInstance = hInstance;
  31.     wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  32.     wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
  33.     wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  34.     wndclass.lpszMenuName = szAppName;
  35.     wndclass.lpszClassName = szAppName;
  36.  
  37.     RegisterClass(&wndclass);
  38.   }
  39.  
  40.   hwnd = CreateWindow(szAppName, "Device Capabilities",
  41.                       WS_OVERLAPPEDWINDOW,
  42.                       CW_USEDEFAULT, CW_USEDEFAULT,
  43.                       CW_USEDEFAULT, CW_USEDEFAULT,
  44.                       NULL, NULL, hInstance, NULL);
  45.  
  46.   ShowWindow(hwnd, nCmdShow);
  47.   UpdateWindow(hwnd);
  48.  
  49.   while(GetMessage(&msg, NULL, 0, 0))
  50.   {
  51.     TranslateMessage(&msg);
  52.     DispatchMessage(&msg);
  53.   }
  54.   return msg.wParam;
  55. }
  56.  
  57. HDC GetPrinterIC()
  58. {
  59.   char szPrinter[64];
  60.   char *szDevice, *szDriver, *szOutput;
  61.  
  62.   GetProfileString("windows", "device", "", szPrinter, 64);
  63.  
  64.   if ((szDevice = strtok(szPrinter, ",")) &&
  65.       (szDriver = strtok(NULL, ",")) &&
  66.       (szOutput = strtok(NULL, ",")))
  67.         return CreateIC(szDriver, szDevice, szOutput, NULL);
  68.  
  69.   return NULL;
  70. }
  71.  
  72. long FAR PASCAL WndProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
  73. {
  74.   static short cxChar, cyChar, nCurrentDevice = IDM_SCREEN,
  75.                                nCurrentInfo = IDM_BASIC;
  76.  
  77.   HDC hdc, hdcInfo;
  78.   HMENU hMenu;
  79.   PAINTSTRUCT ps;
  80.   TEXTMETRIC tm;
  81.  
  82.   switch (message)
  83.   {
  84.     case WM_CREATE:
  85.       hdc = GetDC(hwnd);
  86.       SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
  87.       GetTextMetrics(hdc, &tm);
  88.       cxChar = tm.tmAveCharWidth;
  89.       cyChar = tm.tmHeight + tm.tmExternalLeading;
  90.       ReleaseDC (hwnd, hdc);
  91.       return 0;
  92.  
  93.     case WM_COMMAND:
  94.       hMenu = GetMenu(hwnd);
  95.       switch (wParam)
  96.       {
  97.         case IDM_SCREEN:
  98.         case IDM_PRINTER:
  99.           CheckMenuItem(hMenu, nCurrentDevice, MF_UNCHECKED);
  100.           nCurrentDevice = wParam;
  101.           CheckMenuItem(hMenu, nCurrentDevice, MF_CHECKED);
  102.           InvalidateRect(hwnd, NULL, TRUE);
  103.           return 0;
  104.  
  105.         case IDM_BASIC:
  106.         case IDM_OTHER:
  107.         case IDM_CURVE:
  108.         case IDM_LINE:
  109.         case IDM_POLY:
  110.         case IDM_TEXT:
  111.           CheckMenuItem(hMenu, nCurrentInfo, MF_UNCHECKED);
  112.           nCurrentInfo = wParam;
  113.           CheckMenuItem(hMenu, nCurrentInfo, MF_CHECKED);
  114.           InvalidateRect(hwnd, NULL, TRUE);
  115.           return 0;
  116.       }
  117.       break;
  118.  
  119.     case WM_DEVMODECHANGE:
  120.       InvalidateRect(hwnd, NULL, TRUE);
  121.       return 0;
  122.  
  123.     case WM_PAINT:
  124.       hdc = BeginPaint(hwnd, &ps);
  125.       SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
  126.       if (nCurrentDevice == IDM_SCREEN)
  127.         hdcInfo = CreateIC("DISPLAY", NULL, NULL, NULL);
  128.       else
  129.         hdcInfo = GetPrinterIC();
  130.  
  131.       if (hdcInfo)
  132.       {
  133.         switch (nCurrentInfo)
  134.         {
  135.           case IDM_BASIC:
  136.             DoBasicInfo(hdc, hdcInfo, cxChar, cyChar);
  137.             break;
  138.  
  139.           case IDM_OTHER:
  140.             DoOtherInfo(hdc, hdcInfo, cxChar, cyChar);
  141.             break;
  142.  
  143.           case IDM_CURVE:
  144.           case IDM_LINE:
  145.           case IDM_POLY:
  146.           case IDM_TEXT:
  147.             DoBitCodedCaps(hdc, hdcInfo, cxChar, cyChar,
  148.                            nCurrentInfo - IDM_CURVE);
  149.             break;
  150.         }
  151.         DeleteDC(hdcInfo);
  152.       }
  153.       EndPaint(hwnd, &ps);
  154.       return 0;
  155.  
  156.     case WM_DESTROY:
  157.       PostQuitMessage(0);
  158.       return 0;
  159.   }
  160.   return DefWindowProc(hwnd, message, wParam, lParam);
  161. }
  162.